package Test.拷贝;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Order implements Cloneable{
    
    //订单ID
    private String orderId;
    //收货地址
    private Address shippingAddress;

    //重写clone
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public Order deepCopy() {
        //深拷贝、新new一个地址对象出来
        Address newAddress = new Address(this.shippingAddress.getProvince(), this.shippingAddress.getCity());
        return new Order(this.orderId, newAddress);
    }
}
//
//@Data
//@AllArgsConstructor
//@NoArgsConstructor
//public class Order implements Serializable {
//
//    private String orderId;
//    private Address shippingAddress;
//
//    public  Order deepCopy(Order order) {
//        //序列化实现深拷贝
//        return SerializationUtils.clone(order);
//    }
//}